/*
 *  $Id: Accept.cs 1217 2010-11-27 10:48:54Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Serialization;

namespace Ragima.Events {
    [TypeId("accept"), ConstructorParameters("_accept")]
    public class Accept : DirectConnectEvent {
        [Serialize, XmlName("accept")]
        private readonly bool _accept;

        public Accept(bool accept) {
            _accept = accept;
        }

        protected override void ExecuteInner(DirectConnectScene scene) {
            if (_accept) {
                scene.Log.Add(Resources.DirectConnect.ConnectAccept);
                if (!scene.Mode.Player2.HasAvatar || scene.Mode.Player2.AvatarExists) {
                    scene.Log.Add(Resources.DirectConnect.AvatarFound);
                    scene.CheckDeckRequest();
                } else {
                    scene.Log.Add(Resources.DirectConnect.AvatarRequest);
                    scene.Mode.SendEvent(new Avatar(true, scene.Mode.Player2.AvatarFileName));
                }
            } else {
                scene.Log.Add(Resources.DirectConnect.ConnectReject);
                scene.Mode.DisconnectGame();
            }
        }
    }
}
